package com.base.library.coroutine

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

private class MainScope(override val coroutineContext: CoroutineContext = Dispatchers.Main) :
    CoroutineScope

private class MainSupervisorScope(override val coroutineContext: CoroutineContext = Dispatchers.Main) :
    CoroutineScope

private val mainSupervisorScope: MainSupervisorScope by lazy { MainSupervisorScope() }
private val mainScope: MainScope by lazy { MainScope() }

/**
 * start main coroutine
 */
fun main(block: suspend CoroutineScope.() -> Unit) =
    mainScope.launch {
        block()
    }

/**
 * start main coroutine
 */
fun mainSupervisor(block: suspend CoroutineScope.() -> Unit) =
    mainSupervisorScope.launch {
        block()
    }